<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <!--使用局部组件-->
    <login :username="name" @fun1="fun2"></login>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
    let login = {
        template: "<div><h1>欢迎，{{uName}}</h1> <hr> <button @click='fun'>点我</button></div>",
        //组件内数据(必须为一个函数)
        data() {
            return {
                uName:this.username
            }
        },
        props:["username"],
        methods: {
            fun() {
                //调用其他组件传来的函数
                this.$emit("fun1");
            }
        }
    }
    const app = new Vue({
        el: "#app",
        data: {  //父组件通过v-bind向子组件传递数据
            name:"yaya"
        },
        methods: {
            fun2() {  //父组件通过v-on向子组件传递函数
                alert(666);
            }
        },
        //在components中注册局部组件
        components: {
            login: login
        }
    })
</script>
</body>
</html>